<?php
declare (strict_types = 1);

namespace app\admin\validate\admin;

use think\Validate;

class User extends BaseUser
{

    private array $allowedModifyFields = ['status'];

    protected $rule = [
        'ids' => 'require|array',
        'ids.*' => 'number|gt:0',

        'id'    => 'require|integer|gt:0',
        'field' => 'require|string',
    ];

    protected $message = [
        'ids.require' => 'ID 不能为空',
        'ids.array'   => 'ID 必须是数组格式',
        'ids.*.number' => 'ID 必须是数字',
        'ids.*.gt'    => 'ID 无效',

        'id.require'    => '用户ID不能为空',
        'id.integer'    => '用户ID必须是整数',
        'field.require' => '要修改的字段名不能为空',
    ];


    protected $scene = [
        'index' => ['*'],
        'add' =>  ['*'],
        'update' => ['*'],
        'delete' => ['ids'],
        // modify
    ];

    public function sceneModify()
    {
        return $this->only(['id', 'field', 'value'])
            ->append('field', 'in:' . implode(',', $this->allowedModifyFields));
    }
}
